package web.Node;

import dao.User_Dao;
import dao.impl.User_DaoImpl;
import domain.Node;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/checkNodeServlet")
public class CheckNodeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*设置页面编码*/
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        //获取页面请求参数
        String IMEI = request.getParameter("IMEI");

        //查询节点是否存在
        String IMEICheck="false" ;
        User_Dao dao = new User_DaoImpl();
        List<Node> nodeCheck = dao.selectAllNode();
        for(Node s:nodeCheck){
            if (IMEI.equals (s.getIMEI())){
                IMEICheck = "true";
            }
        }
        //响应
        response.getWriter().write(IMEICheck);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
